.Button {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 2.5rem;
  padding: 0 0.875rem;
  margin: 0;
  outline: 0;
  border: 1px solid var(--color-gray-200);
  border-radius: 0.375rem;
  background-color: var(--color-gray-50);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.5rem;
  color: var(--color-gray-900);
  user-select: none;

  @media (hover: hover) {
    &:hover {
      background-color: var(--color-gray-100);
    }
  }

  &:active {
    background-color: var(--color-gray-100);
  }

  &:focus-visible {
    outline: 2px solid var(--color-blue);
    outline-offset: -1px;
  }
}

.Backdrop {
  position: fixed;
  min-height: 100dvh;
  inset: 0;
  background-color: black;
  opacity: 0.2;
  transition: opacity 150ms cubic-bezier(0.45, 1.005, 0, 1.005);

  @supports (-webkit-touch-callout: none) {
    position: absolute;
  }

  @media (prefers-color-scheme: dark) {
    opacity: 0.7;
  }

  &[data-starting-style],
  &[data-ending-style] {
    opacity: 0;
  }
}

.Popup {
  box-sizing: border-box;
  position: fixed;
  width: 24rem;
  top: 5rem;
  max-width: calc(100vw - 3rem);
  max-height: min(32rem, calc(100dvh - 6rem));
  padding: 1.5rem;
  border-radius: 0.5rem;
  outline: 1px solid var(--color-gray-200);
  background-color: var(--color-gray-50);
  color: var(--color-gray-900);
  display: flex;
  justify-content: center;
  flex-direction: column;
  overflow: hidden;
  transition:
    opacity 0.25s,
    transform 0.25s;

  @media (prefers-color-scheme: dark) {
    outline: 1px solid var(--color-gray-300);
  }

  &[data-starting-style],
  &[data-ending-style] {
    opacity: 0;
    transform: translateY(-1rem);
  }
}

.Title {
  margin-top: -0.375rem;
  margin-bottom: 0.25rem;
  font-size: 1.125rem;
  line-height: 1.75rem;
  letter-spacing: -0.0025em;
  font-weight: 500;
}

.Description {
  margin-bottom: 1rem;
  font-size: 1rem;
  line-height: 1.5rem;
  color: var(--color-gray-600);
}

.Actions {
  display: flex;
  justify-content: end;
  gap: 1rem;
}

.Label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 500;
  color: var(--color-gray-900);
  position: relative;
}

.InputWrapper {
  position: relative;

  &:has(.Clear) .Input {
    padding-right: calc(0.5rem + 1.5rem * 2);
  }
}

.Input {
  box-sizing: border-box;
  padding-left: 0.875rem;
  padding-right: calc(0.5rem + 1.5rem);
  margin: 0;
  border: 1px solid var(--color-gray-200);
  width: 100%;
  height: 2.5rem;
  border-radius: 0.375rem;
  font-family: inherit;
  font-size: 1rem;
  background-color: canvas;
  color: var(--color-gray-900);

  &:focus {
    outline: 2px solid var(--color-blue);
    outline-offset: -1px;
  }
}

.Chips {
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.125rem;
  border: 1px solid var(--color-gray-200);
  border-radius: 0.375rem;
  padding: 0.25rem 0.375rem;
  min-height: 2.5rem;
  background-color: canvas;
  width: 100%;

  &:focus-within {
    outline: 2px solid var(--color-blue);
    outline-offset: -1px;
  }
}

.Chip {
  display: flex;
  align-items: center;
  background-color: var(--color-gray-100);
  color: var(--color-gray-900);
  border-radius: 0.375rem;
  font-size: 0.875rem;
  padding: 0.25rem 0.25rem 0.25rem 0.5rem;
  gap: 0.25rem;
  outline: 0;
  cursor: default;

  &:focus-within {
    background-color: var(--color-blue);
    color: var(--color-gray-50);
  }

  @media (hover: hover) {
    &[data-highlighted] {
      background-color: var(--color-blue);
      color: var(--color-gray-50);
    }
  }
}

.ChipRemove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  border-radius: 0.375rem;
  padding: 0.125rem;
  color: inherit;

  @media (hover: hover) {
    &:hover {
      background-color: var(--color-gray-200);
    }
  }
}

.ChipRemoveIcon {
  width: 0.75rem;
  height: 0.75rem;
}

.ChipsInput {
  flex: 1;
  min-width: 6rem;
  border: none;
  height: 2rem;
  padding-left: 0.5rem;
  margin: 0;
  font: inherit;
  color: var(--color-gray-900);
  background: none;

  &:focus {
    outline: none;
  }
}

.Results {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 0.25rem;
  overflow: hidden;
}

.List {
  box-sizing: border-box;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-block: 0.5rem;
  scroll-padding-block: 0.5rem;
  outline: 0;
  max-height: min(23rem, 60vh);
  margin: 0;
  flex: 1;
  min-height: 0;

  &[data-empty] {
    padding: 0;
  }
}

.Item {
  box-sizing: border-box;
  outline: 0;
  cursor: default;
  user-select: none;
  padding-block: 0.5rem;
  padding-left: 1rem;
  padding-right: 2rem;
  display: grid;
  gap: 0.5rem;
  align-items: center;
  grid-template-columns: 0.75rem 1fr;
  font-size: 1rem;
  line-height: 1rem;

  &[data-highlighted] {
    z-index: 0;
    position: relative;
    color: var(--color-gray-50);
  }

  &[data-highlighted]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.5rem;
    border-radius: 0.25rem;
    background-color: var(--color-gray-900);
  }
}

.ItemText {
  grid-column-start: 2;
}

.ItemIndicator {
  grid-column-start: 1;
}

.ItemIndicatorIcon {
  display: block;
  width: 0.75rem;
  height: 0.75rem;
}

.Empty:not(:empty) {
  font-size: 0.925rem;
  line-height: 1rem;
  color: var(--color-gray-600);
  padding: 1rem;
  border-radius: 0.375rem;
  background-color: var(--color-gray-100);
}

.Viewport {
  display: flex;
  justify-content: center;
  align-items: center;
}
